<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sponsorship {
	private $CI;
	
	public function __construct() {
		$this->CI = &get_instance();
		$this->CI->load->model('Sponsorship_Model', 'sponsorshipmodel');
	}
	
	public function get_sponsor_info($username) {
		return $this->CI->sponsorshipmodel->get_sponsor_info($username);
	}
	
	public function edit_sponsor_info($id, $name, $address, $contactName, $contactNo) {
		if ($this->CI->authentication->is_allowed('EDIT_SPONSOR_INFO')) {
			return $this->CI->sponsorshipmodel->edit_sponsor_info($id, $name, $address, $contactName, $contactNo);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function add_sponsor($name, $address, $contactName, $contactNo, $user, $username, $password) {
		if ($this->CI->authentication->is_allowed('EDIT_SPONSOR_INFO')) {
			return $this->CI->sponsorshipmodel->add_sponsor($name, $address, $contactName, $contactNo, $user, $username, $password);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function change_password($username, $old, $new) {
		if ($this->CI->authentication->is_allowed('EDIT_SPONSOR_INFO')) {
			return $this->CI->sponsorshipmodel->change_password($username, $old, $new);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function get_sponsors($name = '') {
		return $this->CI->sponsorshipmodel->get_sponsors($name);
	}
	
	public function get_sponsor_info_by_id($id) {
		return $this->CI->sponsorshipmodel->get_sponsor_info_by_id($id);
	}
	
	public function get_sponsor_user($id) {
		return $this->CI->sponsorshipmodel->get_sponsor_user($id);
	}
	
}